//package com.mi.soul.whale.common.service.impl;
//
//import com.mi.soul.whale.common.Interceptor.Auth;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.logging.log4j.util.StringMap;
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Service;
//import org.springframework.web.multipart.MultipartFile;
//
///**
// * 七牛云oss存储文件
// *
// * @author 作者 mallplus E-mail: 951449465@qq.com
// */
//@Slf4j
//@Service("qiniuOssServiceImpl")
//public class QiniuOssServiceImplI extends AbstractIFileService implements InitializingBean {
//    @Autowired
//    private UploadManager uploadManager;
//    @Autowired
//    private BucketManager bucketManager;
//    @Autowired
//    private Auth auth;
//    @Value("${qiniu.oss.bucketName:xxxxx}")
//    private String bucket;
//    @Value("${qiniu.oss.endpoint:xxxxx}")
//    private String endpoint;
//    private StringMap putPolicy;
//
//    @Override
//    protected FileType fileType() {
//        return FileType.QINIU;
//    }
//
//    @Override
//    protected void uploadFile(MultipartFile file, FileInfo fileInfo) throws Exception {
//        // 调用put方法上传
//        uploadManager.put(file.getBytes(), fileInfo.getName(), auth.uploadToken(bucket));
//        fileInfo.setUrl(endpoint + "/" + fileInfo.getName());
//        fileInfo.setPath(endpoint + "/" + fileInfo.getName());
//    }
//
//    @Override
//    protected boolean deleteFile(FileInfo fileInfo) {
//        try {
//            Response response = bucketManager.delete(this.bucket, fileInfo.getPath());
//            int retry = 0;
//            while (response.needRetry() && retry++ < 3) {
//                response = bucketManager.delete(bucket, fileInfo.getPath());
//            }
//        } catch (QiniuException e) {
//            return false;
//        }
//        return true;
//    }
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//        this.putPolicy = new StringMap();
//        putPolicy.put("returnBody",
//                "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"bucket\":\"$(bucket)\",\"width\":$(imageInfo.width), \"height\":${imageInfo.height}}");
//    }
//}
